/**
 * 
 * 移动零
 * https://leetcode-cn.com/problems/move-zeroes/
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var moveZeroes = function (nums) {

    let i
    let len = nums.length
    let zeroCount = 0
    let notZeroCount = 0

    for (i = 0; i < len; i++) {
        if (!nums[i]) {
            zeroCount++
        } else {
            notZeroCount++
            nums[i - zeroCount] = nums[i]
        }
    }
    i = notZeroCount
    while (i < len) {
        nums[i++] = 0
    }

};

let inputArr = [0, 1, 0, 3, 12]
moveZeroes(inputArr)
console.log(inputArr)

//================v1要点总结===============
/**
 * 1. 思想：分别统计零的个数和非零的个数，在非零时，将该值前移当前零个数的长度，最后将后面赋值为0
 */